<?php
/**
 * @title 392. 判断子序列 - 双指针
 * @author start2004
 */

class Solution {

    /**
     * @param String $s
     * @param String $t
     * @return Boolean
     */
    function isSubsequence($s, $t) {
        /**
         * @since 2020-07-27 长度
         */
        $lenS = strlen($s);
        $lenT = strlen($t);

        /**
         * @since 2020-07-27 极端情况
         */
        if($lenS == 0){
            return true;
        } else {}

        /**
         * @since 2020-07-27 遍历
         */
        for ($i=0, $j=0; $i<$lenT; $i++){
            /**
             * @since 2020-07-27 移动`s`指针
             */
            if($t[$i] == $s[$j]){
                $j++;

                /**
                 * @since 2020-07-27 `s`匹配完成
                 */
                if($j == $lenS){
                    return true;
                    break;
                } else {}
            } else {}
        }

        /**
         * @return
         */
        return false;
    }
}




/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.27.php
 */
$datas = [
    ["abc", "ahbgdc"],
    ["axc", "ahbgdc"],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->isSubsequence($data[0], $data[1]);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
